/**
 * @(#)AppUpdateDataMan.java, 2014年10月13日. Copyright 2012 Yodao, Inc. All rights
 *                            reserved. YODAO PROPRIETARY/CONFIDENTIAL. Use is
 *                            subject to license terms.
 */
package com.scitc.pleasurevideo.data;

import com.scitc.pleasurevideo.util.TimeUtil;
import com.scitc.pleasurevideo.x5webview.MyApplication;

/**
 * @author lukun 解析数据为对象
 */
public class SystemSettingDataMan{

	private static SystemSettingDataMan dataMan;

	private SystemSettingDataMan() {
		super();
	}

	public synchronized static SystemSettingDataMan getDataMan() {
		if (dataMan == null) {
			dataMan = new SystemSettingDataMan();
		}
		return dataMan;
	}

	public void settingCloseTime(long dura) {
		ETMan.savePref(MyApplication.getInstance(),"timer_setting_time_point", System.currentTimeMillis() + dura);
	}

	public boolean isShouldClose() {
		long time = ETMan.getPref(MyApplication.getInstance(),"timer_setting_time_point", System.currentTimeMillis() + 86400 * 1000*365);
		long interval = time - System.currentTimeMillis();
		if (interval <= 0 && interval >= -1000*10) {
			return true;
		}
		return false;
	}
	
	public void closeApp(){
		ETMan.savePref(MyApplication.getInstance(),"timer_setting_time_point", System.currentTimeMillis() + 86400 * 1000 * 36);
		ETMan.savePref(MyApplication.getInstance(),"timer_setting_time", 0);
	}

	public String getSettingCloseTime() {
		long time = ETMan.getPref(MyApplication.getInstance(),"timer_setting_time_point", System.currentTimeMillis() + 86400 * 100 * 365 * 50);
		long interval = time - System.currentTimeMillis();
		if (interval > 86400000 || interval < 0) {
			return null;
		}
		String lastTime = TimeUtil.getLeftTime((int) interval);
		return lastTime + "后关闭";
	}

	public int getTimerSettingTime() {
		return ETMan.getPref(MyApplication.getInstance(),"timer_setting_time", 0);
	}

	public void saveTimerTime(int type, long dura) {
		ETMan.savePref(MyApplication.getInstance(),"timer_setting_time", type);
		settingCloseTime(dura);
	}

}
